package cc.eddic.practice.spring.domain;

import cc.eddic.practice.spring.QuestionType;
import cc.eddic.practice.spring.jpa.BaseEntity;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.*;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

@Entity
@EntityListeners(AuditingEntityListener.class)
@Table(name = "t_question")
@Builder
@Getter
@ToString
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class Question extends BaseEntity {
    private String description;
    private QuestionType questionType;
    public Question(String description){
        this.description=description;
        options=new ArrayList<>();
    }
    public Question add(Option option){
        option.setQuestion(this);
        options.add(option);
        return this;
    }
    @JsonIgnore
    @ToString.Exclude
    @OneToMany(mappedBy = "question",cascade = CascadeType.ALL,fetch = FetchType.LAZY)
    private List<Option> options;

}
